home *** CD-ROM | disk | FTP | other *** search
- /****************************************************************************************
- *
- * GE_Utilities.c Useful odd bits
- *
- * created 1/7/91 from recoverd files
- * 23/12/91 IsAResource function added.
- * 19/2/92 copied for use with generic editor.
- *
- ****************************************************************************************/
-
- #include "PDPGlobalEqu.p"
- #include "QDOffscreen.h"
- #include "GE_Utilities.proto.h"
-
-
-
- CopyString(Ptr s1,Ptr s2)
- {
- short byteCount;
-
- byteCount=*s1+1;
- BlockMove(s1,s2,byteCount);
- }
-
-
- ConcatString(Ptr s1,Ptr s2)
- {
- /* given pointers to two pascal strings, this function concatenates the characters of
- s2 on to the end of s1. No range checking is performed. */
-
- short byteCount,offset;
- Ptr temp;
-
- temp=s1; /* remember old pointer */
- offset=*s1+1; /* length of first string */
- s1+=offset; /* point at end of string +1 */
- byteCount=*s2; /* length of second string */
- s2++; /* first char of second string */
- BlockMove(s2,s1,byteCount); /* copy chars */
- *temp=offset+byteCount-1; /* update length */
- }
-
-
- SetWatchCursor(void)
- {
- /* call to set watch cursor whenever a lengthy operation is to be called. The normal
- AdjustCursor call will automatically return the cursor to its correct appearance
- once the operation has terminated. */
-
- CursHandle watch;
-
- watch=GetCursor(watchCursor);
- if (watch!=NIL)
- SetCursor(*watch);
- }
-
-
- short ShiftDown(void)
- {
- /* returns TRUE if shift key down */
-
- KeyMap theKeys;
-
- GetKeys(&theKeys);
- return(theKeys[1] & 1);
- }
-
-
- short OptionDown(void)
- {
- /* returns TRUE if option key down */
-
- KeyMap theKeys;
-
- GetKeys(&theKeys);
- return(theKeys[1] & 4);
- }
-
-
- short CommandDown(void)
- {
- /* returns TRUE if command key down */
-
- KeyMap theKeys;
-
- GetKeys(&theKeys);
- return(theKeys[1] & 32768);
- }
-
-
- short ControlDown(void)
- {
- /* returns TRUE if control key down */
-
- KeyMap theKeys;
-
- GetKeys(&theKeys);
- return(theKeys[1] & 8);
- }
-
-
- CentreRects(Rect *r1,Rect *r2)
- {
- /* Offsets the coordinates of r2 so that it is centred with respect to r1. r1 is not
- changed. Rectangles can be different sizes or same size */
-
- int dH,dV;
-
- dH=((r1->right-r1->left)-(r2->right-r2->left))/2 - r2->left + r1->left;
- dV=((r1->bottom-r1->top)-(r2->bottom-r2->top))/2 - r2->top + r1->top;
- OffsetRect(r2,dH,dV);
- }
-
-
- long GetNudgeDistance(void)
- {
- /* if any of the arrow keys are down, the function returns the equivalent offset as
- its result as if it was a pixel offset. HiWord is vertical offset, LoWord is
- horizontal. If no keys down it returns zero. Can be used to implement graphic
- nudging with the arrow keys. */
-
- KeyMap theKeys;
- long dH,dV;
-
- GetKeys(&theKeys);
- dH=0;dV=0;
- if (theKeys[3] & 64)
- dV=0x0000FFFF;
- if (theKeys[3] & 32)
- dV=1;
- if (theKeys[3] & 8)
- dH=0x0000FFFF;
- if (theKeys[3] & 16)
- dH=1;
- return((long)(dV <<16 | dH));
- }
-
-
- DebugKeys(void)
- {
- KeyMap theKeys;
- Str255 kStr;
- Rect kBox;
-
- GetKeys(&theKeys);
- NumToString(theKeys[3],&kStr);
- SetRect(&kBox,20,40,100,60);
- TextBox(&kStr[1],kStr[0],&kBox,teJustLeft);
- }
-
-
- SetDefaultOpColour(CGrafPtr theWindow)
- {
- /* sets OpColor of port to 50% grey */
- RGBColor blendWeight;
- CGrafPtr savePort;
- GDHandle saveDevice;
-
-
- GetGWorld(&savePort,&saveDevice);
- SetGWorld(theWindow,saveDevice);
- blendWeight.red = blendWeight.green = blendWeight.blue = 0x7FFF;
- OpColor(&blendWeight);
- SetGWorld(savePort,saveDevice);
- }
-
-
- AlignToZero(Rect *theRect)
- {
- /* Offsets rect so that it's top,left coordinate is 0,0. Size is unchanged. */
-
- OffsetRect(theRect,-theRect->left,-theRect->top);
- }
-
-
- MarkForUpdate(WindowPtr theWindow)
- {
- /* invalidates the entire portrect of the window specified */
- GrafPtr savePort;
-
- if (theWindow!=NIL) {
- GetPort(&savePort);
- SetPort(theWindow);
- InvalRect(&thePort->portRect);
- SetPort(savePort);
- }
- }
-
-
- AlignRgnToZero(RgnHandle theRgn)
- {
- /* offsets region to align top, left to 0,0 */
- Rect rB;
-
- if (theRgn!=NIL) {
- rB=(**theRgn).rgnBBox;
- OffsetRgn(theRgn,-rB.left,-rB.top);
- }
- }
-
-
- SetIndMenuItem(MenuHandle theMenu,int theItem,int strListID,int strListItem)
- {
- /* sets the menu item specified to the string in the string list specified */
- Str255 mString;
-
- GetIndString(&mString,strListID,strListItem);
- if (mString[0]>0 && theMenu!=NIL)
- SetItem(theMenu,theItem,&mString);
- }
-
-
- SetIndParamText(int strListID,int strListItem)
- {
- /* sets first param text item to the string in the string list specified */
- Str255 mString;
-
- GetIndString(&mString,strListID,strListItem);
- ParamText(&mString,"\p","\p","\p");
- }
-
-
- DrawIndString(int strListID,int strListItem)
- {
- /* calls drawstring with indexed string specified */
-
- Str255 mStr;
-
- GetIndString(&mStr,strListID,strListItem);
- DrawString(&mStr);
- }
-
-
- int IsAResource(Handle theRes)
- {
- /* returns true if given handle is a resource, else false */
- long temp;
-
- temp = RsrcMapEntry(theRes);
- if (ResError()==resNotFound)
- return(FALSE);
- else
- return(TRUE);
- }
-
-
-
-